Connecting to VM Instance
Introduction to SSH clients, RDP client and firewall
We'll cover the following
Connecting to instance#
In this lesson, we will learn how to connect to the Linux instance as well as to a Windows instance.
Linux#
To connect to the Linux instance, we use SSH. This is the simplest method to connect to a Linux instance. Google Cloud provides in-browser SSH support. Click on the SSH button next to the instance.
The instance name can different for you.
Using SSH CLI clients#
You can also use gcloud ssh client to ssh into the instance. To use the gcloud ssh client, open the terminal and follow the steps.
-
Set the right project to use. Type
gcloud config set project [project ID]. -
Type
gcloud compute ssh --zone us-central1-a [username]@[instance_name/host_name].
For example, if the instance name is “demo-instance” and the user is “demo” then you will write:
$ gcloud compute ssh --zone us-central1-a demo@demo-instance
Hit enter for a blank passphrase while creating ssh keys.
This command will add your local ssh keys to the project-wide metadata section. And then you can use the same ssh keys to SSH into other VM instances.
To check the project-wide ssh keys,
Go to the settings section of Compute Engine > Metadata and then select the SSH keys. This section will list all the ssh keys added for this project.
Third Party Client
Normally, you would not be using project-wide SSH keys in production, and most of the time project-wide ssh keys are disabled for security reasons. In this case, you need to manage the ssh keys for your instances.
So, you will use the instance’s SSH keys section to add ssh key and use the ssh client to SSH into the instance.
To create an ssh key we will use the ssh-keygen CLI tool.
- Type,
ssh-keygen -t rsa -f demo -C demo.
This will create the public and private keys in the current folder. Copy the contents of the demo.pub file and add those to the ssh section of the instance.
- Go to the instance page. Click on the instance name. Click the edit button.
- Go to ssh keys section and expand it.
- Paste the
demo.pubfile contents as it is.
- Now, using the command line type
ssh -i demo demo@[IP of instance]
The -i is for the location/path of the private key. In this case, demo in the above command is the name of the file. Since the command is run in the same directory, we can provide the name of the file as it is.
You should be able to ssh into the instance using the above command. You can use the below terminal to SSH into the instance using the above method.
Windows#
Creating a windows instance is the same as creating a Linux instance. The only obvious change is you need to select the “Windows Operating System” instead of the default Debian for boot disk of the instance. The minimum requirement for the Windows OS is 1vCPU and >=3.75 GB RAM.
To connect to a windows instance we need to use a different approach. Windows instance is connected using the RDP client.
-
Download any RDP client for your OS from here. Or you can install the RDP extension for chrome browser.
-
Set the Windows username & copy the generated password in the console. To set the Windows password, click on the inverted triangle icon beside the RDP button in Connect column.
- Click on the RDP button. Download the RDP file to connect to the instance and click it. If you don’t have an RDP client you can install the RDP extension in the browser itself. You can install the RDP client from Microsoft’s official website as well.
- Click on the downloaded RDP connection file, Once you click it, you will be prompted to enter the username and password. Enter the username and the earlier copied password.
If everything goes right you will see the Windows desktop.
Cleanup#
To avoid extra billing, make sure you keep deleting the instances after completing the demo. This will make sure that you will not exhaust the free credits and does not get charged.
Creating Compute Engine VMs
Creating Compute Instance Group